#include "StdAfx.h"
#include "BindIDManagerImpl.h"
#include "../LibUtil/LibUtil.h"
USING_LIB_UTIL

BIND_ID_NAMESPACE_BEGIN

BindIDManagerImpl::BindIDManagerImpl(void)
{
}

BindIDManagerImpl::~BindIDManagerImpl(void)
{
}

void BindIDManagerImpl::Initialize(const string& orgID, const string& platformID)
{
	m_orgID = orgID;
	m_platformID = platformID;
}

tBindInfo BindIDManagerImpl::ConvertToBindInfo(const string& orgID, 
												const string& platformID,
												const string& primaryKey,
												const string& secondaryKey)
{
	tBindInfo bindInfo;
	bindInfo.textInfo = "orgID:" + m_orgID;
	bindInfo.textInfo += ",platformID:" + m_platformID;
	bindInfo.textInfo += ",primaryKey:" + primaryKey;
	bindInfo.textInfo += ",secondaryKey:" + secondaryKey;

	tDataBuffer buffer(bindInfo.textInfo);
	MD5HashHelper::GetDataBufferHashInt128(buffer, bindInfo.bindKey.primaryKey, bindInfo.bindKey.secondaryKey);
	return bindInfo;
}

tBindInfo BindIDManagerImpl::ConvertToBindInfo(const string& primaryKey, const string& secondaryKey)
{
	return ConvertToBindInfo(m_orgID, m_platformID, primaryKey, secondaryKey);
}

tBindInfo BindIDManagerImpl::ConvertToBindInfo(const IBindingObject* bindingObject)
{
	tBindInfo& bindInfo = ConvertToBindInfo(m_orgID, m_platformID, bindingObject->GetPrimaryKey(), bindingObject->GetSecondaryKey());
	if(bindingObject->GetTextInfo().length() > 0)
		bindInfo.textInfo = bindingObject->GetTextInfo();
	return bindInfo;
}

BIND_ID_NAMESPACE_END